<template>
  <el-drawer :title="title" :visible.sync="visible" size="360px" direction="rtl" @close="handleClose">
    <el-row>
      <el-col :span="24">
        <el-form ref="assginForm" :model="form" :rules="rules" label-position="top" label-width="80px">
          <el-form-item prop="owner">
            <select-user-by-dept v-model="form.owner" placeholder="请选择指派人" multi />
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <div class="el-drawer__footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="handleSubmit">{{ loading ? '提交中 ...' : '确 定' }}</el-button>
    </div>
  </el-drawer>
</template>

<script>
import SelectUserByDept from '@/components/Zrk/SelectUserByDept'
export default {
  name: 'AssginDrawer',
  components: { SelectUserByDept },
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: '指派客户',
      visible: this.show,
      form: {
        owner: ''
      },
      loading: false,
      rules: {
        owner: [{ required: true, message: '指派人不能为空', trigger: 'blur' }]
      }
    }
  },
  watch: {
    show: {
      immediate: true,
      handler(val) {
        this.visible = this.show
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.assginForm.validate((valid) => {
        if (valid) {
          console.log(JSON.stringify(this.form))
        }
      })
    },
    handleClose() {
      this.$refs.assginForm.resetFields()
      this.$emit('update:show', false)
    }
  }
}
</script>
